#region - Class details -
/*  
 *  Developer   : Wicus Botha
 *  Description : 
 *  History     : WB - 2008-06-05 - Created
 */
#endregion

using System;
using log4net;

namespace IQ.Base.Services
{
	public static class Logging
	{
        #region - Private methods -
        //private static readonly ILog Log = LogManager.GetLogger(LogName);
		/**
		* Log levels
		* 				Debug	Info	Warn	Error	Fatal
		* Debug (debug)	X		X		X		X		X
		* Info	(info)	-		X		X		X		X
		* Warn	(warn)	-		-		X		X		X
		* Error (error)	-		-		-		X		X
		* Fatal (fatal)	-		-		-		-		X
		* 
		* ALL (all)		X		X		X		X		X
		* OFF (off)		-		-		-		-		-
		*/
        private static ILog Log()
		{
			return LogManager.GetLogger(LogName);
        }
        private static ILog Log(string logname)
		{
			return LogManager.GetLogger(logname);
        }
        #endregion

        #region - Public variable -
        public static string LogName = "";
//        public static string LogName = AppDomain.CurrentDomain.FriendlyName.Remove(AppDomain.CurrentDomain.FriendlyName.IndexOf('.'));
       	#endregion
       	
		#region - Public methods -
		public static void ConfigureLog()
        {
            log4net.Config.XmlConfigurator.Configure();
        }
        public static void SetModuleId(int modId)
        {
            log4net.GlobalContext.Properties["ModID"] = modId;
        }

		public static void Debug(string message)
		{
			ILog log = Log();
            if (log.IsDebugEnabled)
                log.Debug(message);
		}

		public static void Error(string message)
		{
			ILog log = Log();
            if (log.IsErrorEnabled)
                log.Error(message);
			//string exception = "error";
            //    Log.Error(message, exception);			
		}

		public static void Info(string message)
        {
			ILog log = Log();
            if (log.IsInfoEnabled)
                log.Info(message);
        }	
	
		public static void Warn(string message)
		{
			ILog log = Log();
            if (log.IsWarnEnabled)
                log.Warn(message);
		}
		public static void Warn(string logname, string message)
		{
			ILog log = Log(logname);			
			//MDC.Set("ModID","111");
            if (log.IsWarnEnabled)
                log.Warn(message);
		}
		
        #endregion	
	}
}